<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <input type="text" name="name" id="name" placeholder=" 名称" value="<{$Think.get.name}>" style="width:250px" class="input-text">
             <button id="search" class="btn btn-success" type="button"><i class="Hui-iconfont"></i> 搜索</button>
            <a href="javascript:;" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a>
            <a class="btn btn-primary radius" data-title="添加仓库" _href="article-add.html" onclick="add()" href="javascript:;"><i class="Hui-iconfont"></i> 添加仓库</a>
			<a class="btn btn-primary radius" data-title="升级" _href="article-add.html" onclick="updateAll()" href="javascript:;">全部升级</a>
			<a class="btn btn-primary radius" data-title="关联角色"  onclick="bind_role()" href="javascript:;">关联角色</a>
			<a class="btn btn-primary radius" data-title="审核" onclick="examined(1)" href="javascript:;">审核通过</a>
			<a class="btn btn-primary radius" data-title="审核" onclick="examined(2)" href="javascript:;">审核不通过</a>
        </span>
        <span class="r">共有数据：<strong><{$count}></strong> 条</span>
    </div>
    <div class="mt-20">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                <thead>
                <tr class="text-c" role="row">
                    <th width="25" style="width: 25px;"><input type="checkbox" name="" value=""></th>
                    <th width="80" class="" style="width: 120px;">ID</th>
                    <th tabindex="0" style="width: 157px;">仓库名称</th>
					<th tabindex="0" style="width: 97px;">手机号</th>
					<th tabindex="0" style="width: 97px;">昵称</th>
                    <th width="120" style="width: 120px;">仓库编码</th>
					<th width="120" style="width: 120px;">角色</th>
                    <th width="120" style="width: 220px;">添加时间</th>
					<th width="60" style="width: 70px;">审核状态</th>
                    <th width="120" style="width: 220px;">操作</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="list" item="data">
                    <tr class="text-c odd" role="row">
                        <td>
							<input type="checkbox" value="<{$data.id}>" class="ids" name="">
						</td>
                        <td class=""><{$data.id}></td>
                        <td class="text-l">
						<a href="javascript:;" style="color:red" onclick="manage('<{$data.warehouse_code}>')" >管理</a>
						&nbsp;&nbsp;&nbsp;&nbsp;
						<span tabindex="<{$data.id}>" onclick="sp_show(this)" style="width: 90%; padding: 4px 12px; "><{$data.name}></span>
						</td>
						<td><{$data.username}></td>
						<td><{$data.nick_name}></td>
                        <td><{$data.warehouse_code}></td>
						<td width="120" style="width: 120px;"><{$data.department_name}></td>
                        <td>
							<{$data.created_at}>
						</td>
						<td width="120" style="width: 120px;">
						 <if condition="$data.status eq 0">
							未审核
						 </if>
						 <if condition="$data.status eq 1">
							审核通过
						 </if>
						 <if condition="$data.status eq 2">
							审核未通过
						 </if>
						 </td>
                        <td>
                            <a class="btn btn-success radius" data-title="基本配置" _href="article-add.html" onclick="config('<{$data.id}>')" href="javascript:;">基本配置</a>
							<a style="text-decoration:none" class="ml-5" onclick="edit_warehouse('<{$data.id}>')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a>
                            <a style="text-decoration:none" class="ml-5" onclick="del('<{$data.id}>')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>
                        </td>
                    </tr>
                </foreach>
                </tbody>
            </table>
            <div class="page">
                <{$page}>
            </div>
        </div>
    </div>
    </div>
    <script id="add_text" type="text/html">
        <div style="padding: 12px;">
            <table>
                <tr>
                    <td width="60" height="40">仓库名称</td>
                    <td><input type="text" name="warehouse_name" class="input-text" /></td>
                </tr>
                <tr>
                    <td width="60">仓库编码</td>
                    <td><input type="text" value="<{:rand(10000000,99999999)}>" readonly style="background:#ccc" name="warehouse_code" class="input-text" /></td>
                </tr>
                <tr>
					<td width="60" height="40">手机号码：</td>
					<td>
						<input  onFocus="this.value = '';" name="username"  onBlur="if (this.value == '') {this.value = '';}"  value=""  type="text" class="input-text">
					</td>
				</tr>
				<tr>
					<td width="60" height="40">昵称：</td>
					<td>
						<input  onFocus="this.value = '';" name="nick_name"  onBlur="if (this.value == '') {this.value = '';}"  value=""  type="text" class="input-text">
					</td>
				</tr>
				  <tr>
					<td width="60" height="40">密码：</td>
					<td><input  onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}"  value=""  type="password" name="pwd" class="input-text">
					</td>
				  </tr>
      
				  <tr>
					<td width="60" height="40">重复密码：</td>
					<td><input  onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}"  value=""  type="password" name="pwd2" class="input-text">
					</td>
				  </tr>
				  <tr>
					<td width="60" height="40">仓库类型：</td>
					<td>
						<select class="easyui-combobox warehouse_cate input-text" name="warehouse_cate" style="width:282px;height:38px;">
								<option value="0">未选择</option>
								<foreach name="department_list" item="vo">
									<option value="<{$vo.id}>"><{$vo.name}></option>
								</foreach>
						</select>
					<td>
				  </tr>
            </table>
        </div>
    </script>
    <script id="interface" type="text/html">
        <div style="padding: 12px;">
            <table>
                <tr>
                    <td width="90" height="40">地址名称</td>
                    <td><input type="text" class="input-text" /></td>
                </tr>
                <tr>
                    <td height="120">URL地址</td>
                    <td><textarea style="height:100px;" type="text" class="input-text"></textarea></td>
                </tr>
                <tr>
                    <td>变量名称</td>
                    <td><input type="text" class="input-text" /></td>
                </tr>
            </table>
        </div>
    </script>
	
    <include file="Public/footer" />
    <include file="Public/footer_js" />
    <script>
		function manage(warehouse_code){
			host_url="<{:C('WMS_URL')}>";
			index_url="/index.php?s=/index/index";
			url="/index.php?s=/Login/admin_manage";
			$.ajax({
				url:host_url+url,
				data:{warehouse_code:warehouse_code},
				type:"post",
				success:function(data){
					console.log(data);
					if(data.status){
						layer.msg("登录成功，正在跳转",function(){
							window.open(host_url+index_url);
						});
					}else{
						layer.msg(data.message);
					}
				}
			})
		}
	    function edit_warehouse(id){
			var index=layer.open({
				type: 2,
				title: '仓库修改',
				shadeClose: true,
				shade: 0.5,
				area: ['400px', '400px'],
				content: '__MODULE__/Warehouse/edit/id/'+id //iframe的url
			});
		}
		function examined(val){
				var option = $(".ids");
				var checked_counts=0;
				var check_val = [];
				for(var i=0;i<option.length;i++){
					if(option[i].checked){
						checked_counts++;
						check_val.push(option[i].value);
					}
				}
				if(checked_counts==0){
					layer.msg('至少选中一个');
					return false;
				}else{
					 $.post('__CONTROLLER__/examined',{
						ids:check_val,
						val:val
					},function(msg){
						layer.msg(msg.data,function(){
							location.reload();
						});
					},'json');
				}
		}
		function bind_role(){
				var option = $(".ids");
				var checked_counts=0;
				var check_val = [];
				for(var i=0;i<option.length;i++){
					if(option[i].checked){
						checked_counts++;
						check_val.push(option[i].value);
					}
				}
				if(checked_counts==0){
					layer.msg('至少选中一个');
					return false;
				}else{
					var index=layer.open({
					  title: '选择角色组',
					  type: 2,
					  area: ['300px', '280px'], //宽高
					  content: '__MODULE__/Warehouse/bind_role_warehouse/ids/'+check_val //iframe的url
					});
				}
		}
        $("#search").click(function (){
            location.href="__CONTROLLER__/index/name/"+$("#name").val();
        });
        var m=0;//防止blur事件多次触发
        function sp_show(_this){
            var value=$(_this).html();
            $(_this).attr('contenteditable',true);
            $(_this).css({'border':'#ddd solid 1px','padding':'2px 8px','background-color':'#fbb'});
            $(_this).bind('blur',function (){
                if(m!=0){
                    return false;
                }
                $(_this).attr('contenteditable',false);
                $(_this).css({'border':'none','padding':'2px 8px','background-color':'#fff'});
                if(value==$(_this).html()){
                    return false;
                }
                m=1;
                $.post('__MODULE__/Warehouse/editD',{
                    name:$(_this).html(),
                    id:$(_this).attr('tabindex'),
                },function (msg){
                    layer.msg(msg.data);
                    m=0;
                    if(msg.flag==1){
                        value=$(_this).html();
                    }
                },'json');
            });
        }
		
		//清空数据
		function truncateAll(id){
			<!-- alert(id); -->
			layer.confirm('点击确定将清空此仓库数据库数据', {
			  btn: ['确定','取消'] //按钮
			}, function(index){
				layer.close(index);
				layer.open({
				  type: 2,
				  title: '清空数据',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['380px', '90%'],
				  content: "__MODULE__/Warehouse/truncateAll/id/"+id //iframe的url
				});
			});
		}
		//数据升级
		function updateAll(_this){
			layer.confirm('点击确定将升级所有仓库数据库', {
			  btn: ['确定','取消'] //按钮
			}, function(index){
				layer.confirm('升级后不能撤销！请再次确认!', {
				  btn: ['确定','取消'] //按钮
				},function(){
					layer.close(index);
					layer.open({
					  type: 2,
					  title: '数据导入',
					  shadeClose: true,
					  shade: 0.8,
					  area: ['380px', '90%'],
					  content: '__MODULE__/Warehouse/updateAll' //iframe的url
					});
				});
			});
		}
        function edit(_this){
            sp_show($(_this).parent().parent().find('span'));
        }
        function add(){
            var index=layer.open({
                type: 1,
                title:'添加仓库',
                skin: 'layui-layer-rim', //加上边框
                area: ['440px', '400px'], //宽高
                content: $("#add_text").html(),
                btn:['确定','取消'],
                id:'post_add',
                yes:function (){
					if($("#post_add input:eq(0)").val()==''){
						layer.msg('仓库名称不能为空');
						return false;
					}
					if($("#post_add input:eq(1)").val()==''){
						layer.msg('仓库编码不能为空');
						return false;
					}
					if($("#post_add input:eq(2)").val()==''){
						layer.msg('手机号不能为空');
						return false;
					}
					if($("#post_add input:eq(3)").val()==''){
						layer.msg('昵称不能为空');
						return false;
					}
					if($("#post_add input:eq(4)").val()==''){
						layer.msg('密码不能为空');
						return false;
					}
					if($("#post_add select").val()==0){
						layer.msg('仓库类型未选择');
						return false;
					}
					if($("#post_add input:eq(4)").val()!=$("#post_add input:eq(5)").val()){
						layer.msg('两次输入密码不相同！');
						return false;
					}
					var warehouse_name=$("#post_add input:eq(0)").val();
					var warehouse_code=$("#post_add input:eq(1)").val();
                    var username=$("#post_add input:eq(2)").val();
					var nick_name=$("#post_add input:eq(3)").val();
                    var pwd=$("#post_add input:eq(4)").val();
					var warehouse_cate=$("#post_add select").val();
                    $.post('__MODULE__/Warehouse/addD',{
                        warehouse_name:warehouse_name,
                        warehouse_code:warehouse_code,
						username:username,
						nick_name:nick_name,
						pwd:pwd,
						warehouse_cate:warehouse_cate,
                    },function (msg){
                        layer.msg(msg.data);
                        if(msg.flag==1){
                            setTimeout(function (){
                                location.reload();
                            },800);
                        }
                    },'json');
                }
            });
        }
        function config(id){
            layer.open({
                type: 2,
                title: '基本配置',
                shadeClose: true,
                shade: 0.8,
                area: ['800px', '600px'],
                content: '__CONTROLLER__/config/id/'+id+'/'+Math.random() //iframe的url
            });
        }
        function delAll(){
            var all_ipt=$("#DataTables_Table_0_wrapper input[type=checkbox]:checked");
            var group_id='';
            for(var i=0;i<all_ipt.length;i++){
                if(all_ipt.eq(i).val()!==''){
                    group_id+='@'+all_ipt.eq(i).val();
                }
            }
            if(group_id.substring(1)==''){
                layer.msg('请勾选要删除的信息');
                return false;
            }
            del(group_id.substring(1));
        }
        function del(id){
			layer.confirm('删除用户将删除数据库，不能恢复！请谨慎操作！',function(){
				layer.confirm('请再次确认，注意此操作不能恢复！',function(){
					$.get('__MODULE__/Warehouse/del',{
						id:id,
					},function (msg){
						if(msg.flag==1){
							layer.msg(msg.data);
							setTimeout(function (){
								location.reload();
							},800);				
						}
					},'json');
				})
			});
        }
    </script>
</body>
</html>